/**
*  \file endian_read.h
*
*  \brief Read integer values from address considering the byte order.
*
*  \author Michael J. Hohmann  michael.hohmann@linde-mh.de
*
*
*
*
*
*/
#ifndef ENDIAN_READ_H_INCLUDED
#define ENDIAN_READ_H_INCLUDED

/*================================================[ public includes  ]================================================*/
#include "../cfg/prj.h"
#include "../pal/pal.h"
/*================================================[ public defines   ]================================================*/

/*================================================[ public datatypes ]================================================*/

/*================================================[ public variables ]================================================*/

/*================================================[ inline functions ]================================================*/

/*================================================[    U16           ]================================================*/

#if PAL_ENDIAN == PAL_ENDIAN_BIG
STATIC_INLINE U16 endian_read_u16_little(void const* adr )
#else
STATIC_INLINE U16 endian_read_u16_big(void const* adr )
#endif
{
	U16 rv;
	pal_memcpy_reverse_2(&rv,adr);
	return rv;
}

#if PAL_ENDIAN == PAL_ENDIAN_BIG
STATIC_INLINE U16 endian_read_u16_big(void const* adr )
#else
STATIC_INLINE U16 endian_read_u16_little(void const* adr )
#endif
{
	U16 rv;
	pal_memcpy_2(&rv,adr);
	return rv;
}

/*================================================[    S16           ]================================================*/

#if PAL_ENDIAN == PAL_ENDIAN_BIG
STATIC_INLINE S16 endian_read_s16_little(void const* adr )
#else
STATIC_INLINE S16 endian_read_s16_big(void const* adr )
#endif
{
	S16 rv;
	pal_memcpy_reverse_2(&rv,adr);
	return rv;
}

#if PAL_ENDIAN == PAL_ENDIAN_BIG
STATIC_INLINE S16 endian_read_s16_big(void const* adr )
#else
STATIC_INLINE S16 endian_read_s16_little(void const* adr )
#endif
{
	S16 rv;
	pal_memcpy_2(&rv,adr);
	return rv;
}



/*================================================[    U32           ]================================================*/

#if PAL_ENDIAN == PAL_ENDIAN_BIG
STATIC_INLINE U32 endian_read_u32_little(void const* adr )
#else
STATIC_INLINE U32 endian_read_u32_big(void const* adr )
#endif
{
	U32 rv=0;
	pal_memcpy_reverse_4(&rv,adr);
	return rv;
}

#if PAL_ENDIAN == PAL_ENDIAN_BIG
STATIC_INLINE U32 endian_read_u32_big(void const* adr )
#else
STATIC_INLINE U32 endian_read_u32_little(void const* adr )
#endif
{
	U32 rv=0;
	pal_memcpy_4(&rv,adr);
	return rv;
}

/*================================================[    S32           ]================================================*/

#if PAL_ENDIAN == PAL_ENDIAN_BIG
STATIC_INLINE U32 endian_read_s32_little(void const* adr )
#else
STATIC_INLINE U32 endian_read_s32_big(void const* adr )
#endif
{
	S32 rv=0;
	pal_memcpy_reverse_4(&rv,adr);
	return rv;
}

#if PAL_ENDIAN == PAL_ENDIAN_BIG
STATIC_INLINE U32 endian_read_s32_big(void const* adr )
#else
STATIC_INLINE U32 endian_read_s32_little(void const* adr )
#endif
{
	S32 rv=0;
	pal_memcpy_4(&rv,adr);
	return rv;
}

/*====================================================================================================================*/

#endif

/***********************************************************************************************************************
*                             Copyright 2018 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/
